package com.alex.controller;

import com.alex.entity.User;
import com.alex.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * 用户Controller
 *
 * @author Alex.shu
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/list")
    public Object list() {
        return userService.list();
    }

    @PostMapping(value = "/add")
    public Object add() {
        Random random = new Random();
        User user = User.builder()
                .city("北京" + random.nextInt(100))
                .name("Alex.shu" + + random.nextInt(100))
                .build();

        return userService.add(user);
    }
}
